package dcl.software.filesync.server.transfer;

import java.io.IOException;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

@Controller
@RequestMapping(value = "transfer")
public class TransferController {
	@Resource
	private TransferService service;

	@RequestMapping(value = "addfile", method = RequestMethod.POST, headers = "content-type=multipart/form-data")
	@ResponseBody
	public String addFile(@RequestPart(value = "file[]", required = true) final MultipartFile multipartFile,
	        @RequestPart(value = "request", required = true) final String details, @RequestHeader String token) throws IOException {

		service.transferFile(multipartFile, details, token);
		return "dloutsch";
	}
}
